package com.hxd.otc.module.wallet.activity;

import android.view.View;
import android.widget.TextView;

import com.hxd.otc.R;
import com.hxd.otc.base.BaseActivity;
import com.hxd.otc.common.UserHelper;
import com.hxd.otc.module.wallet.bean.WalletCoinRecordBean;
import com.hxd.otc.mvp.base.BasePresenter;
import com.hxd.otc.utils.AddressUtil;
import com.hxd.otc.utils.DateUtil;
import com.hxd.otc.utils.StringUtil;

import java.math.BigDecimal;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 作  者 :  卫广玉
 * 时  间 :  2018/7/6 10:55
 * 描  述 :  钱包详情
 */
public class CoinRecordDetailActivity extends BaseActivity {
    @BindView(R.id.tv_nums)
    TextView tvNums;
    @BindView(R.id.tv_coin_type)
    TextView tvCoinType;
    @BindView(R.id.tv_coin_operate)
    TextView tvCoinOperate;
    @BindView(R.id.tv_trade_address)
    TextView tvTradeAddress;
    @BindView(R.id.tv_trade_all_nums)
    TextView tvTradeAllNums;
    @BindView(R.id.tv_trade_coin_free)
    TextView tvTradeCoinFree;
    @BindView(R.id.tv_trade_coin_free_tips)
    TextView tvTradeCoinFreeTips;
    @BindView(R.id.tv_trade_time)
    TextView tvTradeTime;
    @BindView(R.id.tv_type)
    TextView tvType;
    String[] payStatues;

    private WalletCoinRecordBean.WalletCoinRecordData info;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_wallet_coin_record_detail;
    }

    @Override
    protected void initView() {
    }

    @Override
    protected void initData() {
        info = (WalletCoinRecordBean.WalletCoinRecordData) getIntent().getSerializableExtra("info");
        payStatues = getResources().getStringArray(R.array.wallet_detail_pay_statues);

        BigDecimal amountCoinDecimal = new BigDecimal(info.amountCoin);
        if (info.orderType.equals("1")) {//充值：商户到账的数量=通兑数量-通兑手续费，用户扣除数量=通兑数量
            if (UserHelper.getId().equals(info.fromUserId)) {
                //用户扣除数量=通兑数量
                tvNums.setText(String.format("-%s%s", StringUtil.formatNumber(amountCoinDecimal.doubleValue(), 10, false), info.coinType));
                tvTradeCoinFree.setVisibility(View.GONE);
                tvTradeCoinFreeTips.setVisibility(View.GONE);
                tvType.setText(getString(R.string.recharge_expenditure));
                tvTradeAddress.setText(info.toUserNick);
            } else {
                tvTradeCoinFree.setVisibility(View.VISIBLE);
                tvTradeCoinFreeTips.setVisibility(View.VISIBLE);
                BigDecimal toFeeDecimal = new BigDecimal(info.toFee);
                tvTradeCoinFree.setText(String.format("%s%s", StringUtil.formatNumber(toFeeDecimal.doubleValue(), 10, false), info.coinType));
                //商户到账的数量=通兑数量-通兑手续费
                BigDecimal resultDecimal = amountCoinDecimal.subtract(toFeeDecimal);
                tvNums.setText(String.format("+%s%s", StringUtil.formatNumber(resultDecimal.doubleValue(), 10, false), info.coinType));
                tvType.setText(getString(R.string.mall_recharge_income));
                tvTradeAddress.setText(info.fromUserNick);
            }
        } else {//提现：商户扣除数量=通兑数量+手续费，用户到账数量=通兑数量
            if (UserHelper.getId().equals(info.fromUserId)) {
                //商户扣除数量=通兑数量+手续费
                BigDecimal fromFee = new BigDecimal(info.fromFee);
                BigDecimal resultDecimal = amountCoinDecimal.add(fromFee);
                tvNums.setText(String.format("-%s%s", StringUtil.formatNumber(resultDecimal.doubleValue(), 10, false), info.coinType));
                tvTradeCoinFree.setVisibility(View.VISIBLE);
                tvTradeCoinFreeTips.setVisibility(View.VISIBLE);
                tvTradeCoinFree.setText(String.format("%s%s", StringUtil.formatNumber(fromFee.doubleValue(), 10, false), info.coinType));
                tvType.setText(getString(R.string.withdrawal_expenditure));
                tvTradeAddress.setText(info.toUserNick);
            } else {
                //用户到账数量=通兑数量
                tvNums.setText(String.format("+%s%s", StringUtil.formatNumber(amountCoinDecimal.doubleValue(), 10, false), info.coinType));
                tvTradeCoinFree.setVisibility(View.GONE);
                tvTradeCoinFreeTips.setVisibility(View.GONE);
                tvType.setText(getString(R.string.withdrawal_income));
                tvTradeAddress.setText(info.fromUserNick);
            }
        }
        tvCoinOperate.setText(payStatues[info.status]);
        tvCoinType.setText(info.coinType);
        tvTradeAllNums.setText(info.sourceId);
        tvTradeTime.setText(DateUtil.format(Long.parseLong(info.createTime), DateUtil.YY_MM_DD_HH_MM_SS));
    }

    @OnClick({R.id.tv_trade_all_nums})
    public void onClick(View view) {
        AddressUtil.copyAddress(this, tvTradeAllNums.getText().toString(), getString(R.string.copy_serial_number_successfully));
    }

    @Override
    protected void initEvent() {
    }

    @Override
    protected BasePresenter createPresenter() {
        return null;
    }


}